package nape.shape;
import cx.MixList;
import cx.Algorithm;
import nape.callbacks.Callbackable;
import nape.phys.Body;
import nape.phys.Material;
import nape.shape.Polygon;
import nape.geom.AABB;
import nape.geom.Vec2;
import nape.Config;


















class Shape extends Callbackable {
	
	public static var nextId:Int = 0;
	public var id    :Int;
	
	public static inline var CIRCLE :Int = 0;
	public static inline var POLYGON:Int = 1;
	public var type:Int;
	
	
	public var circle :Circle;
	public var polygon:Polygon;
	public var body   :Body;
	
	CxGenerateMixList(Shape)
	
	public var aabb:AABB;
	
	public var area:Float;
	public var material:Material;
	
	public var group :Int;
	public var sensor:Int;
	
	public var data:Dynamic;
	
	
	
	public function new(?TYPE:Int=0xffff,?MAT:Material,?GROUP:Int=0xffffff,?SENSOR:Int=0) {
		type = TYPE;
		group = GROUP;
		sensor = SENSOR;
		material = if(MAT==null) Config.DEFAULT_MATERIAL else MAT;
		area = 0;
		aabb = new AABB(0,0,0,0);
		
		id = nextId++;
	}
	
	
	
	private inline function transform(dis:Vec2,dst:Vec2) {
		dst.px = body.px + body.ROTX(dis);
		dst.py = body.py + body.ROTY(dis);
	}

	
		
	public inline function updateShape() {
		if(type == CIRCLE) circle.update();
		else              polygon.update();
	}
}